<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<jsp:include page="common/base_body_header.jsp"/>
<%@ include file="common/taglib.jsp" %>
<jsp:include page="common/navbar.jsp"/>
<jsp:include page="common/page_content_pre.jsp"/>
<div class="page-content">
    <div class="col-xs-12">
        <div class="table-responsive">
            <h3>新闻专区</h3>
            <table id="list-table" class="table table-striped table-bordered table-hover" width="100%">
                <thead>
                <tr>
                    <th>标题</th>
                    <th>发布人</th>
                    <th>
                        <i class="icon-time bigger-110 hidden-480"></i>
                        发布时间
                    </th>
                    <th>操作</th>
                </tr>
                </thead>
                <c:choose>
                    <c:when test="${fn:length(newsContentList) > 0}">
                        <c:forEach items="${newsContentList}" var="item">
                            <tr>
                                <td>${item.title}</td>
                                <td>${item.userName}</td>
                                <td>${item.updateDate}</td>
                                <td><a href="${GLOBAL.basePath}/newsContent/detailOfIndex?newsId=${item.newsId}">查看</a></td>
                            </tr>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        暂无新闻
                    </c:otherwise>
                </c:choose>
            </table>
        </div>
    </div>
    <div class="col-xs-12">
        <div class="table-responsive">
            <h3>抢单专区</h3>
            <table id="list-subscribeTable" class="table table-striped table-bordered table-hover" width="100%">
                <thead>
                <tr>
                    <th>客户姓名</th>
                    <th>房源类型</th>
                    <th>预约房源</th>
                    <th>
                        <i class="icon-time bigger-110 hidden-480"></i>
                        预约时间
                    </th>
                    <th>归属</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <div class="col-xs-12">
        <div class="table-responsive">
            <h3>业主委托</h3>
            <table id="list-ownerEntrustmentTable" class="table table-striped table-bordered table-hover" width="100%">
                <thead>
                <tr>
                    <th>客户姓名</th>
                    <th>小区名</th>
                    <th>楼栋号</th>
                    <th>单元号</th>
                    <th>室名</th>
                    <th>房源类型</th>
                    <th>
                        <i class="icon-time bigger-110 hidden-480"></i>
                        预约时间
                    </th>
                    <th>区域</th>
                    <th>归属</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>

<jsp:include page="common/page_content_suf.jsp"/>
<jsp:include page="common/script.jsp"/>
<script type="text/javascript">
var subscribeTable;
var ownerEntrustmentTable;

var subStats;
var subHouseType;

var ownerStats;
var ownerHouseType;

jQuery(function ($) {
    subscribeTable = $('#list-subscribeTable').dataTable({
        "sAjaxSource": "${GLOBAL.basePath}/subscribe/asynList",
        "fnServerData": function (sSource, aDataSet, fnCallback) {
            $.ajax({
                "dataType": 'json',
                "type": "POST",
                "url": sSource,
                "data": aDataSet,
                "success": fnCallback,
                "beforeSend":function (XMLHttpRequest) {
                    layer.load();
                },
                "complete":function (XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                }
            });
        },
        "fnServerParams": function (aoData) {//向服务器传额外的参数
            <c:if test="${not empty aoData}">
            aoData.push(${aoData});
            </c:if>
        },
        "bSort": false,
        "bFilter": false,
        "bServerSide": true,
        "bProcessing": false,
        "bLengthChange": false,
        "bSearching": false,
        "sProcessing": "${GLOBAL.staticImagePath}/loading.gif' />",
        "oLanguage": {
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
            "sInfoEmpty": "No data"
        },
        "aoColumns": [
            {"mDataProp": "customerName"},
            {
                "mDataProp": "houseType", "mRender": function (data, type, full) {
                if (data == 1) {
                    subHouseType = "bsdetail";
                    return "二手别墅";
                }else if (data == 2) {
                    subHouseType = "hzdetail";
                    return "二手豪宅";
                }else{
                    subHouseType = "xpdetail";
                    return "新楼盘";
                }
                }
            },
            {
                "mDataProp": "houseId",  "mRender": function (data, type, full) {
                    return "<a href ="+'${GLOBAL.pagePath}'+subHouseType+'/'+data+" target='_blank'>"+data+"</a>";
                }
            },
            {"mDataProp": "createDate"},
            {"mDataProp": "userName"},
            {
                "mDataProp": "staus", "sWidth":"80px", "mRender": function (data, type, full) {
                    subStats = data;
                    if(data == 1){
                        return "<span class='label label-sm label-info'>未被抢</span>";
                    }else {
                        return "<span class='label label-sm label-success'>已被抢</span>";
                    }
                }
            },
            {
                "mDataProp": "subscribeId", "sWidth": "80px", "mRender": function (data, type, full) {
                    if(subStats != 1){
                       return "";
                    }else{
                        return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                + "<shiro:hasPermission name='index:subscribe'><button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='subClick(this)'>"
                                + "抢"
                                + "</button></shiro:hasPermission>"
                                + "</div>";
                    }
                }
            }
        ]
    });

    ownerEntrustmentTable = $('#list-ownerEntrustmentTable').dataTable({
        "sAjaxSource": "${GLOBAL.basePath}/ownerEntrustment/asynList",
        "fnServerData": function (sSource, aDataSet, fnCallback) {
            $.ajax({
                "dataType": 'json',
                "type": "POST",
                "url": sSource,
                "data": aDataSet,
                "success": fnCallback,
                "beforeSend":function (XMLHttpRequest) {
                    layer.load();
                },
                "complete":function (XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                }
            });
        },
        "fnServerParams": function (aoData) {//向服务器传额外的参数
            <c:if test="${not empty aoData}">
            aoData.push(${aoData});
            </c:if>
        },
        "bSort": false,
        "bFilter": false,
        "bServerSide": true,
        "bProcessing": false,
        "bLengthChange": false,
        "bSearching": false,
        "sProcessing": "${GLOBAL.staticImagePath}/loading.gif' />",
        "oLanguage": {
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
            "sInfoEmpty": "No data"
        },
        "aoColumns": [
            {"mDataProp": "customerName"},
            {"mDataProp": "nbhName"},
            {"mDataProp": "buildingNo"},
            {"mDataProp": "unitNo"},
            {"mDataProp": "roomNo"},
            {
                "mDataProp": "houseType", "mRender": function (data, type, full) {
                    if (data == 1) {
                        ownerHouseType = "bsdetail";
                        return "二手别墅";
                    }else if (data == 2) {
                        ownerHouseType = "hzdetail";
                        return "二手豪宅";
                    }else{
                        ownerHouseType = "xpdetail";
                        return "新楼盘";
                    }
                }
            },
            {"mDataProp": "createDate"},
            {"mDataProp": "userName"},
            {"mDataProp": "districtName"},
            {
                "mDataProp": "staus", "sWidth":"80px", "mRender": function (data, type, full) {
                    ownerStats = data;
                    if(data == 1){
                        return "<span class='label label-sm label-success'>已被抢</span>";
                    }else {
                        return "<span class='label label-sm label-info'>未被抢</span>";
                    }
                }
            },
            {
                "mDataProp": "contractId", "sWidth": "80px", "mRender": function (data, type, full) {
                    if(ownerStats == 1){
                        return "";
                    }else{
                        return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                + "<shiro:hasPermission name='index:owner'><button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='ownerClick(this)'>"
                                + "抢"
                                + "</button></shiro:hasPermission>"
                                + "</div>";
                    }
                }
            }
        ]
    });
});

var subClick = function (obj) {
    layer.confirm("确认抢这个预约单吗？", {
        title: '提示',
        btn: ['确认', '取消'], //按钮
        area: ['auto', 'auto'] //宽高
    }, function () {
        var result = ART.mAjax("${GLOBAL.basePath}/subscribe", "POST", {subscribeId: $(obj).attr("pkId")});
        layer.alert("抢单成功", {icon: 1, title: '提示', btn: ['OK']});
        subscribeTable.fnDraw();
    })
}

var ownerClick = function (obj) {
    layer.confirm("确认抢这个委托单吗？", {
        title: '提示',
        btn: ['确认', '取消'], //按钮
        area: ['auto', 'auto'] //宽高
    }, function () {
        var result = ART.mAjax("${GLOBAL.basePath}/owner", "POST", {contractId: $(obj).attr("pkId")});
        layer.alert("抢单成功", {icon: 1, title: '提示', btn: ['OK']});
        ownerEntrustmentTable.fnDraw();
    })
}
</script>

